package com.ljye.jg.ljye.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ljye.jg.ljye.R;
import com.ljye.jg.ljye.adapter.ViewPagerAdapter;
import com.ljye.jg.ljye.fragment.Fragment_class_management1;
import com.ljye.jg.ljye.fragment.Fragment_class_management2;
import com.ljye.jg.ljye.fragment.Fragment_class_management3;
import com.ljye.jg.ljye.layout.NavitationLayout;

import java.util.ArrayList;
import java.util.List;

public class Activity_Course_Management extends AppCompatActivity {
    public View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.back://返回
                    finish();
                    break;

                default:
                    break;
            }
        }
    };
    private TextView textTitle1;
    private TextView textTitle2;
    private TextView textTitle3;
    private ImageView back;//返回
    private NavitationLayout navitationLayout;//title
    private ViewPager viewPager1;//viewpager
    private String[] titles1 = new String[]{"待上课程", "课程确认", "已上课程"};
    private ViewPagerAdapter viewPagerAdapter1;//适配器
    private List<Fragment> fragments;//集合

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_management);
        initView();
        back.setOnClickListener(listener);
        initPager();
    }

    private void initPager() {
        fragments = new ArrayList<>();
        fragments.add(new Fragment_class_management1());
        fragments.add(new Fragment_class_management2());
        fragments.add(new Fragment_class_management3());
        viewPagerAdapter1 = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
        viewPager1.setAdapter(viewPagerAdapter1);

        //上下文  标题栏  ViewPager 未选中字体颜色 选中字体颜色 未选中字体大小 选中字体大小 当前viewpager的位置  导航条的边距 是否开启滑动
        navitationLayout.setViewPager(this, titles1, viewPager1, R.color.text_gray, R.color.activity_title_color, 14, 14, 0, 30, true);
        navitationLayout.setBgLine(this, 1, R.color.white); //导航背景色
        navitationLayout.setNavLine(this, 3, R.color.activity_title_color, 0);//导航条颜色
        navitationLayout.setOnNaPageChangeListener(new NavitationLayout.OnNaPageChangeListener() {


            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    textTitle1.setTextColor(getResources().getColor(R.color.activity_title_color));
                    textTitle2.setTextColor(getResources().getColor(R.color.text_gray));
                    textTitle3.setTextColor(getResources().getColor(R.color.text_gray));
                } else if (position == 1) {
                    textTitle2.setTextColor(getResources().getColor(R.color.activity_title_color));
                    textTitle1.setTextColor(getResources().getColor(R.color.text_gray));
                    textTitle3.setTextColor(getResources().getColor(R.color.text_gray));
                } else if (position == 2) {
                    textTitle3.setTextColor(getResources().getColor(R.color.activity_title_color));
                    textTitle2.setTextColor(getResources().getColor(R.color.text_gray));
                    textTitle1.setTextColor(getResources().getColor(R.color.text_gray));
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        viewPager1 = (ViewPager) findViewById(R.id.viewpager1);
        navitationLayout = (NavitationLayout) findViewById(R.id.bar1);


        textTitle1 = (TextView) findViewById(R.id.text_title_1);
        textTitle2 = (TextView) findViewById(R.id.text_title_2);
        textTitle3 = (TextView) findViewById(R.id.text_title_3);
    }


}
